<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>区块链拍卖平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        :root {
            --primary-color: #4a6bff;
            --secondary-color: #6c757d;
            --dark-color: #343a40;
            --light-color: #f8f9fa;
            --success-color: #28a745;
            --danger-color: #dc3545;
            --warning-color: #ffc107;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        body {
            background-color: #f5f7fa;
            color: #333;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        /* 导航栏样式 */
        nav {
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            padding: 15px 0;
            position: sticky;
            top: 0;
            z-index: 100;
        }
        
        .nav-container {
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .logo {
            font-size: 24px;
            font-weight: 700;
            color: var(--primary-color);
            display: flex;
            align-items: center;
        }
        
        .logo i {
            margin-right: 10px;
        }
        
        .nav-links {
            display: flex;
            list-style: none;
        }
        
        .nav-links li {
            margin-left: 30px;
        }
        
        .nav-links a {
            text-decoration: none;
            color: var(--dark-color);
            font-weight: 500;
            transition: color 0.3s;
            position: relative;
        }
        
        .nav-links a:hover {
            color: var(--primary-color);
        }
        
        .nav-links a::after {
            content: '';
            position: absolute;
            width: 0;
            height: 2px;
            bottom: -5px;
            left: 0;
            background-color: var(--primary-color);
            transition: width 0.3s;
        }
        
        .nav-links a:hover::after {
            width: 100%;
        }
        
        .wallet-info {
            display: flex;
            align-items: center;
        }
        
        .wallet-address {
            margin-right: 15px;
            font-weight: 500;
            color: var(--dark-color);
        }
        
        .connect-btn {
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            font-weight: 500;
            transition: background-color 0.3s;
        }
        
        .connect-btn:hover {
            background-color: #3a5bef;
        }
        
        /* 主要内容区域 */
        .hero {
            background: linear-gradient(135deg, var(--primary-color), #6a11cb);
            color: white;
            padding: 80px 0;
            text-align: center;
            margin-bottom: 40px;
        }
        
        .hero h1 {
            font-size: 48px;
            margin-bottom: 20px;
        }
        
        .hero p {
            font-size: 20px;
            max-width: 700px;
            margin: 0 auto 30px;
        }
        
        .auction-container {
            display: flex;
            gap: 30px;
            margin-bottom: 50px;
        }
        
        /* 拍卖信息卡片 */
        .auction-info {
            flex: 1;
            background-color: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        
        .auction-info h2 {
            color: var(--primary-color);
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        
        .info-item {
            margin-bottom: 20px;
        }
        
        .info-item h3 {
            color: var(--secondary-color);
            font-size: 16px;
            margin-bottom: 8px;
        }
        
        .info-item p {
            font-size: 24px;
            font-weight: 600;
        }
        
        .countdown {
            font-size: 28px;
            color: var(--danger-color);
            font-weight: 700;
        }
        
        /* 操作面板 */
        .auction-actions {
            flex: 1;
            background-color: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        
        .auction-actions h2 {
            color: var(--primary-color);
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        
        .form-group {
            margin-bottom: 25px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            font-weight: 500;
            color: var(--dark-color);
        }
        
        .form-control {
            width: 100%;
            padding: 12px 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
        }
        
        .btn {
            display: inline-block;
            background-color: var(--primary-color);
            color: white;
            border: none;
            padding: 12px 25px;
            border-radius: 5px;
            cursor: pointer;
            font-weight: 500;
            transition: all 0.3s;
            width: 100%;
            font-size: 16px;
        }
        
        .btn:hover {
            background-color: #3a5bef;
            transform: translateY(-2px);
        }
        
        .btn-secondary {
            background-color: var(--secondary-color);
        }
        
        .btn-secondary:hover {
            background-color: #5a6268;
        }
        
        .btn-success {
            background-color: var(--success-color);
        }
        
        .btn-success:hover {
            background-color: #218838;
        }
        
        .btn-danger {
            background-color: var(--danger-color);
        }
        
        .btn-danger:hover {
            background-color: #c82333;
        }
        
        .btn-disabled {
            background-color: #cccccc;
            cursor: not-allowed;
            opacity: 0.7;
        }
        
        .btn-disabled:hover {
            transform: none;
        }
        
        /* 竞标历史 */
        .bid-history {
            background-color: white;
            border-radius: 10px;
            padding: 30px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            margin-bottom: 40px;
        }
        
        .bid-history h2 {
            color: var(--primary-color);
            margin-bottom: 20px;
            padding-bottom: 10px;
            border-bottom: 1px solid #eee;
        }
        
        .history-table {
            width: 100%;
            border-collapse: collapse;
        }
        
        .history-table th, .history-table td {
            padding: 12px 15px;
            text-align: left;
            border-bottom: 1px solid #eee;
        }
        
        .history-table th {
            background-color: #f8f9fa;
            font-weight: 500;
            color: var(--secondary-color);
        }
        
        .history-table tr:hover {
            background-color: #f5f5f5;
        }
        
        /* 响应式设计 */
        @media (max-width: 992px) {
            .auction-container {
                flex-direction: column;
            }
        }
        
        /* 通知样式 */
        .notification {
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 15px 20px;
            border-radius: 5px;
            color: white;
            z-index: 1000;
            display: flex;
            align-items: center;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
            animation: slideIn 0.3s ease-out;
        }
        
        .notification-success {
            background-color: var(--success-color);
        }
        
        .notification-error {
            background-color: var(--danger-color);
        }
        
        .notification-warning {
            background-color: var(--warning-color);
            color: #333;
        }
        
        @keyframes slideIn {
            from {
                transform: translateX(100%);
                opacity: 0;
            }
            to {
                transform: translateX(0);
                opacity: 1;
            }
        }
        
        .close-btn {
            margin-left: 15px;
            cursor: pointer;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav>
        <div class="container nav-container">
            <div class="logo">
                <i class="fas fa-gavel"></i>
                <span>区块链拍卖</span>
            </div>
            <ul class="nav-links">
                <li><a href="#">首页</a></li>
                <li><a href="#">当前拍卖</a></li>
                <li><a href="#">历史拍卖</a></li>
                <li><a href="#">帮助中心</a></li>
            </ul>
            <div class="wallet-info">
                <span class="wallet-address" id="walletAddress">未连接钱包</span>
                <button class="connect-btn" id="connectBtn">连接钱包</button>
            </div>
        </div>
    </nav>

    <!-- 英雄区域 -->
    <section class="hero">
        <div class="container">
            <h1>稀有数字艺术品拍卖</h1>
            <p>参与我们的区块链拍卖，获取独一无二的数字收藏品。公平、透明、安全的拍卖体验。</p>
            <div class="countdown" id="countdown">00:00:00</div>
        </div>
    </section>

    <!-- 主要内容 -->
    <div class="container">
        <div class="auction-container">
            <!-- 拍卖信息 -->
            <div class="auction-info">
                <h2>拍卖信息</h2>
                <div class="info-item">
                    <h3>当前最高出价</h3>
                    <p id="currentHighestBid">0 ETH</p>
                </div>
                <div class="info-item">
                    <h3>最高出价者</h3>
                    <p id="currentHighestBidder">暂无</p>
                </div>
                <div class="info-item">
                    <h3>拍卖结束时间</h3>
                    <p id="auctionEndTime">--</p>
                </div>
                <div class="info-item">
                    <h3>拍卖状态</h3>
                    <p id="auctionStatus">进行中</p>
                </div>
            </div>

            <!-- 操作面板 -->
            <div class="auction-actions">
                <h2>操作面板</h2>
                <div class="form-group">
                    <label for="bidAmount">出价金额 (ETH)</label>
                    <input type="number" id="bidAmount" class="form-control" placeholder="输入您的出价" min="0" step="0.01">
                </div>
                <button class="btn btn-success" id="placeBidBtn">出价</button>
                <button class="btn btn-secondary" id="withdrawBtn" style="margin-top: 15px; display: none;">提款</button>
                <button class="btn btn-danger" id="endAuctionBtn" style="margin-top: 15px; display: none;">结束拍卖</button>
            </div>
        </div>

        <!-- 竞标历史 -->
        <div class="bid-history">
            <h2>竞标历史</h2>
            <table class="history-table">
                <thead>
                    <tr>
                        <th>出价者</th>
                        <th>金额 (ETH)</th>
                        <th>时间</th>
                    </tr>
                </thead>
                <tbody id="bidHistory">
                    <tr>
                        <td colspan="3" style="text-align: center;">暂无竞标记录</td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>

    <!-- 通知 -->
    <div id="notification" class="notification notification-success" style="display: none;">
        <span id="notificationText">操作成功！</span>
        <span class="close-btn" id="closeNotification">×</span>
    </div>

    <script>
        // 模拟智能合约交互 - 实际应用中应使用web3.js或ethers.js与真实合约交互
        document.addEventListener('DOMContentLoaded', function() {
            // 模拟合约状态
            let contractState = {
                highestBid: 0,
                highestBidder: null,
                bidEndTime: Math.floor(Date.now() / 1000) + 86400, // 24小时后结束
                pendingReturns: {},
                ended: false,
                owner: '0x1234567890abcdef1234567890abcdef12345678',
                bidHistory: []
            };
            
            let isWalletConnected = false;
            let currentAccount = null;
            
            // DOM元素
            const walletAddressEl = document.getElementById('walletAddress');
            const connectBtn = document.getElementById('connectBtn');
            const currentHighestBidEl = document.getElementById('currentHighestBid');
            const currentHighestBidderEl = document.getElementById('currentHighestBidder');
            const auctionEndTimeEl = document.getElementById('auctionEndTime');
            const auctionStatusEl = document.getElementById('auctionStatus');
            const countdownEl = document.getElementById('countdown');
            const bidAmountEl = document.getElementById('bidAmount');
            const placeBidBtn = document.getElementById('placeBidBtn');
            const withdrawBtn = document.getElementById('withdrawBtn');
            const endAuctionBtn = document.getElementById('endAuctionBtn');
            const bidHistoryEl = document.getElementById('bidHistory');
            const notificationEl = document.getElementById('notification');
            const notificationTextEl = document.getElementById('notificationText');
            const closeNotificationEl = document.getElementById('closeNotification');
            
            // 初始化倒计时
            initCountdown();
            setInterval(initCountdown, 1000);
            
            // 更新UI
            updateUI();
            
            // 连接钱包按钮点击事件
            connectBtn.addEventListener('click', async () => {
                // 模拟钱包连接
                isWalletConnected = true;
                currentAccount = '0x' + Math.random().toString(16).substr(2, 40);
                walletAddressEl.textContent = shortenAddress(currentAccount);
                connectBtn.textContent = '已连接';
                connectBtn.style.backgroundColor = '#28a745';
                
                // 检查是否有待退还的金额
                if (contractState.pendingReturns[currentAccount] && contractState.pendingReturns[currentAccount] > 0) {
                    withdrawBtn.style.display = 'block';
                }
                
                showNotification('钱包连接成功！', 'success');
            });
            
            // 出价按钮点击事件
            placeBidBtn.addEventListener('click', () => {
                if (!isWalletConnected) {
                    showNotification('请先连接钱包！', 'error');
                    return;
                }
                
                const bidAmount = parseFloat(bidAmountEl.value);
                if (isNaN(bidAmount) || bidAmount <= 0) {
                    showNotification('请输入有效的出价金额！', 'error');
                    return;
                }
                
                if (bidAmount <= contractState.highestBid) {
                    showNotification(`出价必须高于当前最高价 ${contractState.highestBid} ETH！`, 'error');
                    return;
                }
                
                // 模拟合约出价
                const previousHighestBid = contractState.highestBid;
                const previousHighestBidder = contractState.highestBidder;
                
                contractState.highestBid = bidAmount;
                contractState.highestBidder = currentAccount;
                
                if (previousHighestBid > 0 && previousHighestBidder) {
                    contractState.pendingReturns[previousHighestBidder] = (contractState.pendingReturns[previousHighestBidder] || 0) + previousHighestBid;
                }
                
                // 添加到竞标历史
                contractState.bidHistory.unshift({
                    bidder: currentAccount,
                    amount: bidAmount,
                    timestamp: Math.floor(Date.now() / 1000)
                });
                
                // 重置出价表单
                bidAmountEl.value = '';
                
                // 更新UI
                updateUI();
                
                showNotification(`成功出价 ${bidAmount} ETH！`, 'success');
                
                // 检查提款按钮是否需要显示
                if (contractState.pendingReturns[currentAccount] && contractState.pendingReturns[currentAccount] > 0) {
                    withdrawBtn.style.display = 'block';
                }
            });
            
            // 提款按钮点击事件
            withdrawBtn.addEventListener('click', () => {
                if (!isWalletConnected) {
                    showNotification('请先连接钱包！', 'error');
                    return;
                }
                
                const amount = contractState.pendingReturns[currentAccount] || 0;
                if (amount <= 0) {
                    showNotification('没有可提取的金额！', 'error');
                    return;
                }
                
                // 模拟提款
                delete contractState.pendingReturns[currentAccount];
                withdrawBtn.style.display = 'none';
                
                showNotification(`成功提取 ${amount} ETH！`, 'success');
                updateUI();
            });
            
            // 结束拍卖按钮点击事件
            endAuctionBtn.addEventListener('click', () => {
                if (!isWalletConnected) {
                    showNotification('请先连接钱包！', 'error');
                    return;
                }
                
                if (currentAccount.toLowerCase() !== contractState.owner.toLowerCase()) {
                    showNotification('只有所有者可以结束拍卖！', 'error');
                    return;
                }
                
                if (contractState.ended) {
                    showNotification('拍卖已经结束！', 'error');
                    return;
                }
                
                // 模拟结束拍卖
                contractState.ended = true;
                auctionStatusEl.textContent = '已结束';
                endAuctionBtn.style.display = 'none';
                placeBidBtn.disabled = true;
                placeBidBtn.classList.add('btn-disabled');
                
                showNotification('拍卖已成功结束！', 'success');
                updateUI();
            });
            
            // 关闭通知
            closeNotificationEl.addEventListener('click', () => {
                notificationEl.style.display = 'none';
            });
            
            // 初始化倒计时
            function initCountdown() {
                const now = Math.floor(Date.now() / 1000);
                const remaining = contractState.bidEndTime - now;
                
                if (remaining <= 0) {
                    countdownEl.textContent = '00:00:00';
                    auctionStatusEl.textContent = '已结束';
                    contractState.ended = true;
                    placeBidBtn.disabled = true;
                    placeBidBtn.classList.add('btn-disabled');
                    endAuctionBtn.style.display = 'block';
                    return;
                }
                
                const hours = Math.floor(remaining / 3600);
                const minutes = Math.floor((remaining % 3600) / 60);
                const seconds = remaining % 60;
                
                countdownEl.textContent = `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
            }
            
            // 更新UI
            function updateUI() {
                currentHighestBidEl.textContent = `${contractState.highestBid} ETH`;
                currentHighestBidderEl.textContent = contractState.highestBidder ? shortenAddress(contractState.highestBidder) : '暂无';
                
                const endTime = new Date(contractState.bidEndTime * 1000);
                auctionEndTimeEl.textContent = endTime.toLocaleString();
                
                auctionStatusEl.textContent = contractState.ended ? '已结束' : '进行中';
                
                // 更新竞标历史
                if (contractState.bidHistory.length === 0) {
                    bidHistoryEl.innerHTML = `
                        <tr>
                            <td colspan="3" style="text-align: center;">暂无竞标记录</td>
                        </tr>
                    `;
                } else {
                    let html = '';
                    contractState.bidHistory.forEach(bid => {
                        const date = new Date(bid.timestamp * 1000);
                        html += `
                            <tr>
                                <td>${shortenAddress(bid.bidder)}</td>
                                <td>${bid.amount} ETH</td>
                                <td>${date.toLocaleString()}</td>
                            </tr>
                        `;
                    });
                    bidHistoryEl.innerHTML = html;
                }
                
                // 更新按钮状态
                if (contractState.ended) {
                    placeBidBtn.disabled = true;
                    placeBidBtn.classList.add('btn-disabled');
                    endAuctionBtn.style.display = 'block';
                } else {
                    placeBidBtn.disabled = false;
                    placeBidBtn.classList.remove('btn-disabled');
                    endAuctionBtn.style.display = 'none';
                }
                
                // 如果是所有者且拍卖未结束，显示结束拍卖按钮
                if (isWalletConnected && currentAccount.toLowerCase() === contractState.owner.toLowerCase() && !contractState.ended) {
                    endAuctionBtn.style.display = 'block';
                }
            }
            
            // 显示通知
            function showNotification(message, type) {
                notificationEl.style.display = 'flex';
                notificationTextEl.textContent = message;
                notificationEl.className = `notification notification-${type}`;
                
                setTimeout(() => {
                    notificationEl.style.display = 'none';
                }, 5000);
            }
            
            // 缩短地址显示
            function shortenAddress(address) {
                if (!address) return '';
                return `${address.substring(0, 6)}...${address.substring(address.length - 4)}`;
            }
        });
    </script>
</body>
</html>